<template>
	<view class="">
		<view class="contant"><run-list @toactivedetail="toactivedetail" :runlist="runlist"></run-list></view>
		<!-- loading 遮罩层 -->
		<loading v-if="loadflag"></loading>
		<navigation></navigation>
	</view>
</template>

<script>
import runList from '@/components/index/runlist.vue';
import loading from '@/components/loading/loading.vue';
import navigation from '@/components/navigation/navigation.vue';
export default {
	components: { runList, loading, navigation },
	data() {
		return {
			loadflag: true,
			runlist: [],
			club_id: '',
			currentpage: 1,
			last_page: ''
		};
	},
	onLoad(options) {
		this.club_id = options.id;
	},
	mounted() {
		this.getrunActiveList();
	},
	onReachBottom() {
		if (this.currentpage == this.last_page) {
			this.toast('没有更多数据了');
			return;
		}
		// this.toast('数据加载中');
		uni.showLoading({
			title:'加载中'
		})
		this.currentpage++;
		this.getrunActiveList();
	},
	methods: {
		getrunActiveList() {
			this.ajax('club/clubActive', {
				data: {
					club_id: this.club_id,
					// limit: this.currentpage
					page: this.currentpage
				},
				success: res => {
					 // console.log (res);
					var list = res.msg.data;
					const nowTime = new Date().getTime();
					list.forEach(e => {
						e.startActive = e.start_time.split(' ')[0];
						// 报名开始时时间戳
						e.sign_up_start = e.sign_up_start.replace(/-/g, '/');
						var sing_start = new Date(e.sign_up_start).getTime();
						// 报名结束时间
						e.sign_up_end = e.sign_up_end.replace(/-/g, '/');
						var sing_end = new Date(e.sign_up_end).getTime();
						// 活动开始时间
						e.start_time = e.start_time.replace(/-/g, '/');
						var start_time = new Date(e.start_time).getTime();
						// 活动结束时间
						e.end_time = e.end_time.replace(/-/g, '/');
						var end_time = new Date(e.end_time).getTime();
						if (nowTime < sing_start) {
							e.state = 2;
						} else if (nowTime > sing_start && nowTime < sing_end) {
							e.state = 0;
						} else if (nowTime > start_time && nowTime < end_time) {
							e.state = 4;
						} else if (nowTime > end_time) {
							e.state = 3;
						} else {
							e.state = 1;
						}
					});
					this.last_page = res.msg.last_page;
					this.runlist = this.runlist.concat(res.msg.data);
					this.loadflag = false;
					uni.hideLoading()
				}
			});
		},
		// 活动详情
		toactivedetail(key) {
			uni.navigateTo({
				url: '/pageA/competiondetail/competitiondetail?id=' + key
			});
		}
	}
};
</script>

<style>
page {
	background-color: #ffffff;
}
</style>
<style lang="less" scoped>
.contant {
	width: 100%;
	background-color: #ffffff;
	padding: 0 30upx;
	box-sizing: border-box;
}
</style>
